//
//  TMGHelpTableViewCell.m
//  TMGold
//
//  Created by Mac on 2017/12/11.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGHomeTableViewCell.h"
@interface  TMGHomeTableViewCell()
@property(nonatomic, strong) STButton                     *titleButton;
@property(nonatomic, strong) STLabel                     *yearPecetLabel;
@property(nonatomic, strong) STLabel                     *timePecetLabel;
@property(nonatomic, strong) STLabel                     *yearLable;/**< 时间 */
@property(nonatomic, strong) STLabel                     *timeLable;/**< 买入期限 */
@property(nonatomic, strong) UIView                     *line;/**< 线 */
@end

@implementation TMGHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 100;
}
#pragma mark --subView
- (void)configSubView{
    self.backgroundColor = [UIColor whiteColor];

   self.titleButton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, 200, 44)
                                                     title:@"新手特权金"
                                                titleColor:TM_orangeColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    self.titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self addSubview:self.titleButton];
    self.titleButton.centerY = 22;
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"sy_箭头02"]];
   // [self addSubview:iconButton];
    iconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    iconButton.right = UIScreenWidth - 15;
    
    self.yearPecetLabel = [[STLabel alloc] initWithFrame:CGRectMake(0, self.titleButton.bottom , UIScreenWidth/2, 30)
                                                     text:@"7~8%"
                                                textColor:TM_redColor
                                                     font:22
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [self addSubview:self.yearPecetLabel];
    
    self.timePecetLabel = [[STLabel alloc] initWithFrame:CGRectMake(self.yearPecetLabel.right, self.titleButton.bottom , UIScreenWidth/2, 30)
                                                    text:@"1~10个月"
                                               textColor:TM_redColor
                                                    font:22
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    [self addSubview:self.timePecetLabel];
    
    STLabel * yearLable = [[STLabel alloc] initWithFrame:CGRectMake(0, self.yearPecetLabel.bottom, UIScreenWidth / 2, 16)
                                                     text:@"预计黄金收益率"
                                                textColor:TM_secendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [self addSubview:yearLable];
    self.yearLable = yearLable;
    
    STLabel * timeLable = [[STLabel alloc] initWithFrame:CGRectMake(self.yearPecetLabel.right, self.yearPecetLabel.bottom, UIScreenWidth / 2, 16)
                                                    text:@"买入期限"
                                               textColor:TM_secendTextColor
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    [self addSubview:timeLable];
    self.timeLable = timeLable;
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, self.titleButton.bottom  +15, 1, 30)];
    line.backgroundColor = TM_lineColor;
    line.centerX = UIScreenWidth / 2;
    [self addSubview:line];
    self.line = line;

    
}
- (void)setModel:(TMHomeCellModel *)model{
    _model = model;
    [self.titleButton setImage:[UIImage imageNamed:model.imageName] forState:UIControlStateNormal];
    [self.titleButton setTitle:model.name forState:UIControlStateNormal];
//    self.timePecetLabel.text = [NSString stringWithFormat:@"%@~%@%",model.rate_from,model.rate_to];
//    self.yearPecetLabel.text = [NSString stringWithFormat:@"%@~%@天",model.date_from,model.date_to];
    self.yearPecetLabel.text = [NSString stringWithFormat:@"%@~%@%@",model.rate_from,model.rate_to,@"%"];
    if (model.rate_to.floatValue < 0.1) {
         self.yearPecetLabel.text = [NSString stringWithFormat:@"%@%@",model.rate_from,@"%"];
    }
    self.timePecetLabel.text = [NSString stringWithFormat:@"%@~%@天",model.date_from,model.date_to];
    if ((model.date_from.floatValue < 0.1)&& (model.date_to.floatValue < 0.1)) {
        self.timePecetLabel.text = @"随时起购";
    }
    [self.titleButton setTitleColor:model.thmemeColor forState:UIControlStateNormal];
    self.yearPecetLabel.textColor = model.thmemeColor;
    self.timePecetLabel.textColor = model.thmemeColor;
    
    
    //修改，隐藏1.86% 和预计黄金收益，买入期限 - 实时金价
    self.yearPecetLabel.hidden = YES;
    _yearLable.hidden = YES;
    _line.hidden = YES;
    _timeLable.text = @"实时金价";
//    if ([model.name isEqualToString:@"口袋金"]) {
//        _timePecetLabel.text = @"随时买入";
//    }
    _timePecetLabel.text = @"随时买入";
    _timeLable.centerX = UIScreenWidth / 2;
    _timePecetLabel.centerX = UIScreenWidth / 2;
    _timePecetLabel.textAlignment = NSTextAlignmentCenter;

    
    //59修改，口袋金-黄金商城  随时买入-金项链，金戒指  实时金价-立即购买
    [self.titleButton setTitle:@"黄金商城"
                      forState:UIControlStateNormal];
    _timePecetLabel.text = @"金项链,金戒指";
    _timeLable.text = @"立即购买";
}
@end




